{extend name="base"/}
{block name="main"}
<style>
    .table>tbody>tr>td{
        text-align: center;
    }
</style>
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="n_tab_line">
            <a href="javascript:;" class="n_tab_list">拼团订单</a>
            <div class="cl"></div>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <form class="Huiform" method="post" action="__CONF_SITE__admin/group/group_order" target="_self">
                <div class="text-c"> 订单号：
                    <input type="text" class="input-text" value="{$order_num}" style="width:250px" placeholder="输入订单号"  name="order_num">
                    <button type="submit" class="btn btn-search radius"  name=""><i class="Hui-iconfont">&#xe665;</i> 搜订单</button>
                </div>
            </form>
        </div>
        <div id="tab_demo" class="HuiTab" style="margin-top: 15px;">
            <div class="tabBar clearfix">
                <a href="__CONF_SITE__admin/group/group_order&status=-2"><span {if condition="$status==-2"} class="current" {/if}>全部</span></a>
                <a href="__CONF_SITE__admin/group/group_order&status=1"><span {if condition="$status==1"} class="current" {/if}>未付款</span></a>
                <a href="__CONF_SITE__admin/group/group_order&status=2"><span {if condition="$status==2"} class="current" {/if}>待成团</span></a>
                <a href="__CONF_SITE__admin/group/group_order&status=3"><span {if condition="$status==3"} class="current" {/if}>待发货</span></a>
                <a href="__CONF_SITE__admin/group/group_order&status=4"><span {if condition="$status==4"} class="current" {/if}>待收货</span></a>
                <a href="__CONF_SITE__admin/group/group_order&status=5"><span {if condition="$status==5"} class="current" {/if}>退款中</span></a>
                <a href="__CONF_SITE__admin/group/group_order&status=7"><span {if condition="$status==7"} class="current" {/if}>已退款</span></a>
                <a href="__CONF_SITE__admin/group/group_order&status=6"><span {if condition="$status==6"} class="current" {/if}>已完成</span></a>
            </div>
        </div>
        <table class="table table-border table-bordered table-hover table-bg">
            <thead>
            <tr class="text-c">
                <th>订单编号</th>
                <th>商品</th>
                <th>买家</th>
                <th>收货人</th>
                <th>收货电话</th>
                <th>收货地址</th>
                <th>金额</th>
                <th>数量</th>
                <th>订单状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="list" id="vo"}
            <tr>
                <?php $json=json_ecd_all($vo['address']);
                $json['userName'] = empty($json['userName']) ? '' : $json['userName'];
                $json['telNumber'] = empty($json['telNumber']) ? '' : $json['telNumber'];
                $json['province'] = empty($json['province']) ? '' : $json['province'];
                $json['county'] = empty($json['county']) ? '' : $json['county'];
                $json['city'] = empty($json['city']) ? '' : $json['city'];
                $json['address'] = empty($json['address']) ? '' : $json['address'];
                ?>
                <td>{$vo['orderNum']}</td>
                <td style="text-align: left;"><img src="{:get_img_src($vo['img'])}" style="height: 80px; width: 80px;margin-left:15px;">{$vo.name|subtext=20}</td>
                <td>{:getUserName($vo['uid'])}</td>
                <td>{$json['userName']}</td>
                <td>{$json['telNumber']}</td>
                <td>{$json['province']}{$json['county']}{$json['city']}{$json['address']}</td>
                <td>￥{$vo['totalPrice']}</td>
                <td>{$vo['goodsNum']}</td>
                <td>{:get_group_order_status($vo['order_status'])}</td>
                <td>
                    {if $vo['order_status'] == -1}
                    <a title="删除订单" href="javascript:;" onclick="OrderDel({$vo.id})" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                    {/if}
                    {if $vo['order_status'] == 3}
                    <a title="发货" href="javascript:;" onclick="do_fahuo({$vo.id})" class="ml-5" style="text-decoration:none">商品发货</a>
                    {/if}
                    {if $vo['order_status'] == 5}
                    <a title="确认退款" href="javascript:;" onclick="getderefund({$vo.id})" class="ml-5" style="text-decoration:none">确认退款</a>
                    {/if}
                    <a title="查看详情" href="__CONF_SITE__admin/group/OrderDetail&order_id={$vo.id}" class="ml-5" style="text-decoration:none">查看详情</a>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
    </article>
    <div class="n_page_no">
        {$page}
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    //订单删除
    function OrderDel(id){
        layer.confirm('确认删除这个订单吗？',function(index){
            //此处请求后台程序，下方是成功后的后台处理……
            $.ajax({
                type : "post",
                url : "{:url('group/deleteOrder')}",
                data : {
                    "id" : id,
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        layer.msg('删除成功!',{icon:1,time:1000},function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg('操作失败', {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
    function do_fahuo(id) {
        var msg='确定已发货?';
        layer.confirm(msg,function(){
            $.ajax({
                type : "post",
                url : "{:url('group/group_order_send')}",
                data : {
                    "id" : id
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        layer.msg('操作成功',{icon:1,time:1000},function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
    function getderefund(order_id){
        var refund_type = "<?php echo $refund_type;?>";
        var title = refund_type == 0 ? "系统未配置微信退款, 需要先手动退款给用户, 确定已退款?" : "系统已配置微信退款, 点击确定此订单款项会立即退回用户微信, 是否确认退款?";
        layer.confirm(title,function(index){
            $.ajax({
                type : "post",
                url : "{:url('group/orderTakeRefund')}",
                data : { "id" : order_id },
                success : function(data) {
                    if(data["code"] > 0 ){
                        layer.msg('退款成功', {icon: 1, time: 1000},function () {
                            window.location.reload();
                        });
                    }else {
                        layer.msg(data['message'], {icon: 2, time: 2000});
                    }
                }
            })
        });
    }
</script>
{/block}